package view
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class SubmitAlert extends Sprite
	{
		[Embed(source="assets/tip/submitAlert.png")]
		private var bgCls:Class;
		private var bgBitmap:Bitmap;
		
		private var sureBtn:ImageBtn;
		private var cancleBtn:ImageBtn;
		
		public var container:Sprite;
		public var fun:Function;
		
		private static var instance:SubmitAlert; 
		
		public function SubmitAlert()
		{
			if(instance!=null) throw new Error("Error: Singletons can only be instantiated via getInstance() method!");  
			SubmitAlert.instance = this;  
			init();
		}
		public static function getInstance():SubmitAlert  
		{  
			if(instance==null)  instance = new SubmitAlert();  
			return instance; 
		}
		private function init():void{
			bgBitmap = new bgCls();
			this.addChild(bgBitmap);
			
			sureBtn = new ImageBtn("确定保存");
			this.addChild(sureBtn);
			sureBtn.x = 80;
			sureBtn.y = 80;
			sureBtn.addEventListener(MouseEvent.CLICK,onSure);
			
			cancleBtn = new ImageBtn("我再想想");
			this.addChild(cancleBtn);
			cancleBtn.x = 180;
			cancleBtn.y = 80;
			cancleBtn.addEventListener(MouseEvent.CLICK,onCancle);
		}
		private function onSure(event:MouseEvent):void{
			if(fun != null){
				fun();
			}
			this.remove();
		}
		private function onCancle(event:MouseEvent):void{
			this.remove();
		}
		public function add():void{
			container.addChild(this);//124,278
			this.x = 124;
			this.y = 200;
		}
		public function remove():void{
			container.removeChild(this);
		}
	}
}